//
//  WorkOrder.swift
//  Employee
//
//  Created by swordjoy on 2017/3/23.
//  Copyright © 2017年 remotevillage. All rights reserved.
//

import Foundation
import SwiftyJSON

class WorkOrder: NSObject, NSCoding {
  
  let id: String
  let title: String
  var createTime: String
  var priorityLevel: String
  var status: String
  var timeOut: NSNumber
  
  init(json: JSON) {
    
    id = json["id"].stringValue
    title = json["title"].stringValue
    priorityLevel = json["priorityLevel"].stringValue
    createTime = json["createTime"].stringValue
    timeOut = json["timeout"].numberValue
    status = json["status"].stringValue
    
  }
  
  static func array(from jsonArray: [JSON]) -> [WorkOrder] {
    return jsonArray.map({ (json) -> WorkOrder in
      WorkOrder(json: json)
    })
  }
  
  required init?(coder aDecoder: NSCoder) {
    
    id = (aDecoder.decodeObject(forKey: "id") as? String) ?? ""
    title = (aDecoder.decodeObject(forKey: "title") as? String) ?? ""
    createTime = (aDecoder.decodeObject(forKey: "createTime") as? String) ?? ""
    priorityLevel = (aDecoder.decodeObject(forKey: "priorityLevel") as? String) ?? ""
    timeOut = (aDecoder.decodeObject(forKey: "timeout") as? NSNumber) ?? 0
    status = (aDecoder.decodeObject(forKey: "status") as? String) ?? ""
    
  }
  
  func encode(with aCoder: NSCoder) {
    
    aCoder.encode(id, forKey: "id")
    aCoder.encode(title, forKey: "title")
    aCoder.encode(createTime, forKey: "createTime")
    aCoder.encode(priorityLevel, forKey: "priorityLevel")
    aCoder.encode(timeOut, forKey: "timeout")
    aCoder.encode(status, forKey: "status")
    
  }
  
}

